<?php
declare(strict_types=1);

namespace App\Controller\m1;

use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping;
use Hyperf\HttpServer\Annotation\Middleware;
use Hyperf\Di\Annotation\Inject;
use App\Controller\AbstractController;
use Hyperf\DbConnection\Db;
use App\Constants\ReturnCode;
use Qbhy\HyperfAuth\Annotation\Auth;
use Qbhy\HyperfAuth\AuthManager;
use App\Helper\Common;
use Throwable;
use Overtrue\Flysystem\Qiniu\QiniuAdapter;

#[Controller]
class CommonController extends AbstractController
{
    #获取系统配置
    #[RequestMapping(path: "confs", methods: "post")]
    public function confs(){
        $key = $this->request->input("key", NULL);
        if(empty($key)){
            return $this->fmt_response(ReturnCode::para_miss,'key错误');
        }
        //医院
        if($key=="hospital"){
            $key_words = $this->request->input("key_words", "");
            $data = Common::getHospitalByName($key_words);
        //科室
        }elseif($key=="office"){
            $data = Common::getOfficeConf();
        //其他
        }else{
            $data = Common::getSystemConf($key);
        }
        return $this->fmt_response(ReturnCode::deal_succ,'获取成功',$data);
    }
    #点击统计
    #[RequestMapping(path: "uploadtoken", methods: "post")]
    public function uploadtoken()
    {
        $mod = $this->request->input('mod', NULL);
        if(empty($mod)){
            return $this->fmt_response(ReturnCode::para_miss,'模块错误');
        }
        $accessKey = env('QINIU_ACCESS_KEY');
        $secretKey = env('QINIU_SECRET_KEY');
        $bucket = env('QINIU_BUCKET');
        $domain = env('QINBIU_DOMAIN');
        $adapter = new QiniuAdapter($accessKey, $secretKey, $bucket, $domain);
        $token = $adapter->getUploadToken();
        $return_data = [
            'host' => "https://7img.512xhq.com/",
            'bucket' => "xiaohuquan",
            'path' => "supaiban/".$mod."/".date("Ymd")."/",
            'token' => $token
        ];
        return $this->fmt_response(ReturnCode::deal_succ,'成功',$return_data);
    }
}